#ifndef FORMATITEM_H
#define FORMATITEM_H

#include <QMainWindow>
#include "field/FieldDialog.h"
#include "utils/buffer.h"
#include "format/format.h"

class FormatItem : public QObject
{
    Q_OBJECT

public:
    enum Type {
        kFormat,
        kStructureView,
        kVideoView,
        kAudioView,
        kImageView
    };

    explicit FormatItem(Format *format,
                        FERange range,
                        void *context,
                        FreeContext free,
                        Type type,
                        const QString label,
                        const QString description,
                        FormatItem* parent = nullptr);

    ~FormatItem();

    void constructTree();

    void appendChild(FormatItem* child);

    FormatItem* child(int row);

    int childCount() const;

    int columnCount() const;

    QVariant data(int column) const;

    int row() const;

    FormatItem* parent();

    void show();

public slots:
    int onViewClosed(FieldDialog *obj);

private:
    Format *format_{nullptr};
    FERange range_;
    void *context_{nullptr};
    FreeContext free_{nullptr};
    Type type_;
    QString label_;
    QString description_;
    FormatItem* parent_{nullptr};
    QList<FormatItem*> children_;

    union {
        FieldDialog *structure_{nullptr};
    }view_;
};

#endif // FORMATITEM_H
